<?php
class Tourism_freight_template_model extends CI_Model
{
    private $table   = 'tourism_freight_template';
    private $table_1 = 'tourism_freight_price_list';
    
    public function findByTemplate($param){
        
        $this->db->select('*');
        $this->db->from($this->table.' AS tourism_freight_template');
        $this->db->join($this->table_1.' AS tourism_freight_price_list','tourism_freight_template.id=tourism_freight_price_list.tid','inner');
        if(!empty($param['id'])){
            $this->db->where_in('tourism_freight_template.id',$param['id']);
        }
        if(!empty($param['uid'])){
            $this->db->where_in('tourism_freight_template.uid',$param['uid']);
        }
        if(!empty($param['area'])){
            $area = trim(addslashes($param['area']));
            $sql = "(is_default=1 OR `area` LIKE '%{$area}%' )";
            $this->db->where($sql);
        }
        $this->db->order_by('tourism_freight_price_list.is_default','DESC');
        return $this->db->get();
    }
    
     /**
     * 获取运费模板
     * @param unknown $params
     */
    public function getTransports($params){
    
        $this->db->select('methods,logistics');
        $this->db->from($this->table);
        $this->db->where('uid',$params['uid']);
        $this->db->where('id',$params['id']);
        return $this->db->get()->row();
    }
}